/**
 * 追号记录部分前端代码
 */

// 获取页面数据
var resData = '';
$.ajax({  
	type:'post',    
    url: getDataUrl,  
    data:'operation=chase_detail&oid=' + $('#id_order_id').val(),  
    cache:false,  
    dataType:'json',  
    async:false,
    success:function(res){  
    	resData = res;
    }  
})

console.log(resData);
$('#id_lott_title').html(resData.orderInfo.lott_title);
$('#id_begin_qihao').html(resData.orderInfo.period);
$('#id_chase_pace').html('已追' + resData.orderInfo.open_tims + '期/总' + resData.orderInfo.qishu + '期');
$('#id_winner_stop').html(function (){
	if(resData.orderInfo.winner_end == 1){ return '中奖即停' }else{ return '无'};
});
$('#id_order_time').html(resData.orderInfo.date_createtime);
$('#id_zhui_amount').html(resData.orderInfo.zhuihao_amount + '元');
$('#id_winner_amount').html(resData.orderInfo.winner_amount + '元');
$('#id_order_amount').html(resData.orderInfo.amount);
$('#id_order_no').html(resData.orderInfo.order_no);
$('#id_bet_playInfo td').eq(0).html(resData.orderInfo.cn_play);
$('#id_bet_playInfo td').eq(1).html('<div class="betNum">'+resData.orderInfo.main_code+'</div> <a href="javascript:void(0);" class="NumLink tag_show_detail" amv="' + resData.orderInfo.main_code + '" style="color: rgb(74, 169, 187);">[详情]</a>');
$('#id_bet_playInfo td').eq(2).html(resData.orderInfo.every_qishu_nums);
$('#id_bet_playInfo td').eq(3).html(resData.orderInfo.num);
$('#id_bet_playInfo td').eq(4).html(function (){
	var unit = '';
	switch(resData.orderInfo.money_unit.toString()){
		case '1.00':
			unit = '元';
			break;
		case '0.10':
			unit = '角';
			break;
		case '0.01':
			unit = '分';
			break;
		default:
			unit = '元';
			break;
	}
	return unit;
});
$('#id_bet_playInfo').on('click', '.tag_show_detail', function (){
	showMsg('投注内容', $(this).attr('amv'));
})
$('#id_chase_detail_list').html(function (){
	var winner_status = '';
	$.each(resData.orderInfo.pers, function (i, v){
		console.log(v);
		switch(v.winner.toString()){
			case '1':
				winner_status = '未中奖';
				break;
			case '2':
				winner_status = '已中奖';
				break;
			default:
				winner_status = '未开奖';
				break;
		}
		var tr  = '<tr style="font-size: 12px;">';
			tr += '	<td colspan="1">' + v.period + '</td>';
			tr += '	<td>' + v.multiple + '</td>';
			tr += '	<td>' + v.singel_amount + '</td>';
			tr += '	<td>' + v.open_code + '</td>';
			tr += '	<td>' + winner_status + '</td>';
			tr += '	<td>' + v.winner_amount + '</td>';
			tr += '	<td><a href="javascript:void(0);" class="alink tag_see_more" amv="' + v.bet[0].item_id + '" amp="' + v.period_id + '">查看</a></td>';
			tr += '</tr>';
		$('#id_chase_detail_list').append(tr);
	})
});

$('#id_chase_detail_list').on('click', '.tag_see_more', function (){
	window.location = seeMoreUrl + '&operation=itemmore&oid=' + $(this).attr('amv') + '&pid=' + $(this).attr('amp');
})

/**
 * 计算每期是否中奖
 * @param item
 */
function jisuanChaseWinner(item){
	var winner_status = '';
	var winner_money  = 0;
	$.each(item, function (i, v){
		switch(v.item_winner.toString()){
			case '0':
				winner_status = '未开奖';
				break;
			case '1':
				winner_status = '未中奖';
				break;
			case '2':
				winner_status = '已中奖';
				break;
			default:
				break;
		}
		if(v.item_winner == 2){
			winner_status = '已中奖';
			// 累加中奖金额
			winner_money += v.item_prize;
		}
	})
	return {'winner_status': winner_status, 'winner_money':winner_money};
}

function showMsg(title, content){
	layer.open({
        title: title,
        content: content,
        className: 'layui-m-tag-msg',
        btn: ['确定'],
        yes: function (index){
			// 继续投注
        	layer.close(index);
        },
    });
}





